package com.fyzk.activity.lottery.jc.football.newJz.data;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tyjc.lottery.R;

import java.util.ArrayList;

/**
 * Created by fanxs11 on 16/4/26.
 */
public class ScoreAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<ScoreInfo> infos = new ArrayList<>();

    public ScoreAdapter(Context context, ArrayList<ScoreInfo> infos) {
        this.context = context;
        this.infos = infos;
    }


    @Override
    public int getCount() {
        return infos.size();
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Object getItem(int i) {
        return infos.get(i);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        HolderView holderView;
        final ScoreInfo info = infos.get(i);
        if (view == null) {
            holderView = new HolderView();
            view = LayoutInflater.from(context).inflate(R.layout.score_item, null);
            holderView.week_tv = (TextView) view.findViewById(R.id.score_item_week);
            holderView.home_tv = (TextView) view.findViewById(R.id.score_item_home);
            holderView.score_tv = (TextView) view.findViewById(R.id.score_item_score);
            holderView.away_tv = (TextView) view.findViewById(R.id.score_item_away);
            holderView.status_tv = (TextView) view.findViewById(R.id.score_item_status);
            view.setTag(holderView);
        } else {
            holderView = (HolderView) view.getTag();
        }

        holderView.week_tv.setText("周二 "+info.id+" 瑞典超 00:30");
        holderView.home_tv.setText(info.home);
        holderView.away_tv.setText(info.away);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, ScoreDetailActivity.class);
                intent.putExtra("info", info);
                context.startActivity(intent);
            }
        });
        return view;
    }

    class HolderView{
        TextView week_tv;
        TextView home_tv;
        TextView away_tv;
        TextView score_tv;
        TextView status_tv;
    }
}
